﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using AirLinq.Meta;

namespace AirLinq.Dynamic {
	public class AnonymouseMaterializer<T>: IMaterializer<T> {
		private readonly int _fieldCount;
		
		public AnonymouseMaterializer(int fieldCount){
			if (fieldCount <= 0) {
				throw new ArgumentException("fieldCount less or equal zero");
			}
			
			_fieldCount=fieldCount;
		}
		public T Create(IDataRecord record) {
			var parameters = new object[_fieldCount];
			record.GetValues(parameters);
			//TODO if InternalVisible to this assembly, then make Emit materializer
			return (T)Activator.CreateInstance(typeof(T), parameters);
		}
	}
}
